<?php

define("ORIGINAL_PAGE", '1');

if(!function_exists('echo_debug')) { function echo_debug(){}; }
if(!function_exists('echo_debug_function')) { function echo_debug_function(){}; }
if(!function_exists('write_log')) { function write_log(){}; }

require "../dbconfig.php";
require "../functions/db.class.php";

echo "This may take a while...\n";

$db = new DatabaseConnection($config['databasetype'], 	$config['db_hostname'],  $config['db_user'], $config['db_password'] , $config['database'], TRUE);
$db->connect();

$sql = "SELECT \"ID\" FROM groups WHERE active > 0";
$res = $db->execute_query($sql);

$total = count($res);
$cnt = 0;

foreach($res as $row) {
    $id = $row['ID'];
    $sql = "ALTER TABLE \"binaries_$id\" ADD COLUMN \"dirty\" smallint DEFAULT 0 NOT NULL";
    $db->execute_query($sql);
    $sql = "ALTER TABLE \"parts_$id\" ADD COLUMN \"dirty\" smallint DEFAULT 0 NOT NULL";
    $db->execute_query($sql);

    $sql = "CREATE INDEX \"dirtyp_{$id}_idx\" on \"parts_{$id}\" (\"dirty\")";
    $db->execute_query($sql);
    $sql = "CREATE INDEX \"dirtyb_{$id}_idx\" on \"binaries_{$id}\" (\"dirty\")";
    $db->execute_query($sql);
    $cnt ++;

    echo (floor($cnt * 100/ $total)) . "% done\n";
}

?>
